<!DOCTYPE html>
<html lang="zh-cn">

<head>
    <meta charset="utf-8">
 
    <link href="lib/bootstrap.min.css" rel="stylesheet">
</head>

<body>
    <div class="container">
       
        <form action="index_submit" method="get" accept-charset="utf-8" role="form">
          

 
          

            <h3>测试(json 数据中获取)</h3>
            <p>默认启用空关键字检索。</p>
            <div class="row">
                <div class="col-lg-4">
                    <div class="input-group">
                        <input type="text" class="form-control" id="test_data">
                        <div class="input-group-btn">
                            <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                <span class="caret"></span>
                            </button>
                            <ul class="dropdown-menu dropdown-menu-right" role="menu">
                            </ul>
                        </div>
                        <!-- /btn-group -->
                    </div>
                </div>
            </div>

         
        

        </form>
    </div>
    <script src="lib/jquery.min.js"></script>
    <script src="lib/bootstrap.min.js"></script>
    <script src="lib/bootstrap-suggest.js"></script>
    <script type="text/javascript">
    var testBsSuggest = $("#test").bsSuggest({
        //url: "/rest/sys/getuserlist?keyword=",
        url: "data.json",
        /*effectiveFields: ["userName", "shortAccount"],
        searchFields: [ "shortAccount"],
        effectiveFieldsAlias:{userName: "姓名"},*/
        idField: "userId",
        keyField: "userName"
    }).on('onDataRequestSuccess', function (e, result) {
        console.log('onDataRequestSuccess: ', result);
    }).on('onSetSelectValue', function (e, keyword) {
        console.log('onSetSelectValue: ', keyword);
    }).on('onUnsetSelectValue', function (e) {
        console.log("onUnsetSelectValue");
    });



    /**
     * 从 data参数中过滤数据
     */
    var testdataBsSuggest = $("#test_data").bsSuggest({
        indexId: 2,  //data.value 的第几个数据，作为input输入框的内容
        indexKey: 1, //data.value 的第几个数据，作为input输入框的内容
        data: {
            'value':[
                {'id':'0','word':'lzw','description':'111111'},
                {'id':'1','word':'lzwme','description':'222222'},
                {'id':'2','word':'meizu','description':'333333'},
                {'id':'3','word':'flyme','description':'444444'}
            ],
            'defaults':'nnnnn'
        }
    });
   

    $("form").submit(function(e) {
        return false;
    });
    </script>
</body>

</html>